from collections import OrderedDict

from django.shortcuts import render
from django.views import View

from apps.goods.models import GoodsChannel
from apps.goods.utils import create_categories
from apps.index.models import ContentCategory


class IndexView(View):
    def get(self, request):
        """
        主页
        :param request:
        :return:
        """

        categories_dict = create_categories()
        # 格式 dict = {id:{A:{},B:{,,[C]}   } }
        # 查询主页广告数据
        contents = {}
        content_categories = ContentCategory.objects.all()
        for temp in content_categories:
            contents[temp.key] = temp.content_set.filter(status=True).order_by('sequence')
        # print(contents)

        context = {
            'categories': categories_dict,
            'contents': contents
        }

        return render(request, 'index.html', context=context)
